//
//  MapProxy.m
//  findFriend
//
//  Created by ju on 14-9-13.
//  Copyright (c) 2014年 dono. All rights reserved.
//

#import "MapProxy.h"
#import "JUPeopleAnnotation.h"
#import "JUPeopleAnnotationView.h"
//#import "BMKPointAnnotation.h"
//#import "BMKPinAnnotationView.h"
#import "NSDictionary+Location.h"


@implementation MapProxy
{
    NSMutableDictionary *_annDic;
}

- (id)init
{
    self = [super init];
    if (self) {
        _annDic = [NSMutableDictionary dictionary];
    }
    return self;
}

- (void)updateLocation:(NSDictionary *)dic userId:(NSString *)userId
{
//    BMKPointAnnotation *anno = [_annDic objectForKey:userId];
    JUPeopleAnnotation *anno = [_annDic objectForKey:userId];
    if (anno) {
        [_mapView removeAnnotation:anno];
    }
//    BMKPointAnnotation * newAnno = [[BMKPointAnnotation alloc] init];
    JUPeopleAnnotation *newAnno = [[JUPeopleAnnotation alloc] init];
    newAnno.coordinate = [dic toCoordinate];
    AVUser *user = [[AVUser alloc] init];
    user.username = userId;
    newAnno.user = user;
    [_mapView addAnnotation:newAnno];
    [_annDic setValue:newAnno forKey:userId];
}

#pragma mark 百度地图代理
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[JUPeopleAnnotation class]]) {
        JUPeopleAnnotationView *annView = [[JUPeopleAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"locationAnno"];
//        annView.pinColor = BMKPinAnnotationColorRed;
//        NSLog(@"%@",NSStringFromCGRect(annView.frame));
        return annView;
    }
    return nil;
}

- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view
{
    
}

@end
